home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / sortc.arc / COPY.C next >
Text File  |  1987-06-19  |  2KB  |  78 lines

  1. /*
  2.  *            c o p y . c
  3.  */
  4.  
  5. #ifdef    DOCUMENTATION
  6.  
  7. title    copy    Copy a Given Number of Bytes
  8. index        Copy a given number of bytes
  9.  
  10. synopsis
  11.     .s.nf
  12.     char *
  13.     copy(out, in, nbytes)
  14.     char        *out;    /* Output vector    */
  15.     char        *in;    /* Input vector        */
  16.     unsigned int    count;    /* Bytes to copy    */
  17.     .s.f
  18. Description
  19.  
  20.     Copy the indicated number of bytes from the input area
  21.     to the output area.  Return a pointer to the first free
  22.     byte in the output area.  (I.e., &out[count]).
  23.  
  24.     The copying will be faster if out and in are either both
  25.     even or both odd addresses.
  26.  
  27. Bugs
  28.  
  29.     Warning, this routine "understands" pdp-11 address conventions.
  30. #endif
  31.  
  32. #define   SHIFT   1
  33. #define   LOWBIT   01
  34.  
  35. char *copy(out, in, count)
  36. register char *out;
  37. register char *in;
  38. register unsigned int count;
  39. /*
  40.  * Copy a given number of bytes
  41.  */
  42. {
  43.    if (count != 0)
  44.    {
  45. #ifdef SHIFT
  46.       if (count > 10)
  47.       {
  48.       /*
  49.        * Try to optimize
  50.        */
  51.          if ((((unsigned int) in) & LOWBIT) != 0)
  52.          {
  53.             *out++ = *in++;
  54.             count--;
  55.          }
  56.          if ((((unsigned int) out) & LOWBIT) == 0)
  57.          {
  58.             count >>= SHIFT;   /* Get a word count      */
  59.             do
  60.             {
  61.                *((int *)out)++ = *((int *)in)++;
  62.             } while (--count != 0);
  63.             goto exit;
  64.          }
  65.       }   
  66. #endif
  67.       /*
  68.        * Here for small copies, strange machines, and copies where
  69.        * the output buffer isn't the same parity as the input buffer.
  70.        */
  71.       do
  72.       {
  73.          *out++ = *in++;
  74.       } while (--count != 0);
  75.    }
  76. exit:   return (out);
  77. }
  78.